#include"comm.h"

//创建管道并且读取数据 B
int main()
{
    umask(0);
    if(mkfifo(IPC_FIFO,0660)!=0)
    {
        cout<<"mkfifo err"<<endl;
        exit(-1);
    }
    cout<<"创建管道文件成功"<<endl;

    //只读打开管道文件
    int pipefd = open(IPC_FIFO,O_RDONLY);
    if(pipefd<0)
    {
        cout<<"server :open err"<<endl;
        exit(-1);
    }
    #define SIZE 1024
    char buf[SIZE];
    memset(buf,0,sizeof(buf));
    //读取管道中数据
    int rs = read(pipefd,buf,sizeof(buf)-1);
    if(rs>0)
    {
        buf[rs]='\0';
        cout<<"server 读取到的数据："<<buf<<endl;
    }
    // else if(rs == 0)
    // {
    //     cout<<"客户端已经退出，我也退出"<<endl;
    // }
    else
    {
        cout<<"cerr"<<strerror(errno)<<endl;
    }
}